<template>
  <view class="navbar">
    <view v-if="showBack" class="navbar-back" @click="goBack">
      <text class="iconfont icon-back"></text>
    </view>
    <view v-else style="width: 24px;"></view>
    <view class="navbar-title">{{ title }}</view>
    <view v-if="rightText" class="navbar-right" @click="onRightClick">{{ rightText }}</view>
    <view v-else style="width: 24px;"></view>
  </view>
</template>

<script>
export default {
  name: 'NavBar',
  props: {
    title: {
      type: String,
      default: ''
    },
    showBack: {
      type: Boolean,
      default: true
    },
    rightText: {
      type: String,
      default: ''
    }
  },
  methods: {
    goBack() {
      uni.navigateBack({
        delta: 1
      });
    },
    onRightClick() {
      this.$emit('rightClick');
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 44px;
  background-color: #fff;
  border-bottom: 1px solid $border-color;
  position: sticky;
  top: 0;
  z-index: 1000;
  padding: 0 15px;
  box-sizing: border-box;
  /* #ifdef H5 */
  padding-top: 0;
  /* #endif */
  /* #ifdef MP-WEIXIN */
  padding-top: var(--status-bar-height);
  height: calc(44px + var(--status-bar-height));
  /* #endif */
}

.navbar-title {
  font-size: 18px;
  font-weight: 500;
  text-align: center;
  flex: 1;
}

.navbar-back {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
}

.navbar-right {
  font-size: 14px;
  color: $primary-color;
}

.icon-back:before {
  content: "\e679";
}
</style> 